local extension = Package:new("chui")
extension.extensionName = "Euphonium"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
    ["chui"] = "吹",
}
local jingshangshuncai = General:new(extension,"jingshangshuncai","th_k_chui1",4,4,General.Female)
local wanxianghong = fk.CreateViewAsSkill{
  name = "wanxianghong",
  pattern = ".|.|.|.|.|basic",
  interaction = function()
    local all_names = U.getAllCardNames("b")
    local names = U.getViewAsCardNames(Self, "wanxianghong", all_names)
    if #names > 0 then
      return UI.ComboBox { choices = names, all_choices = all_names }
    end
  end,
    card_filter = function(self, to_select, selected)
        if #selected > 1 then
            return false
        end
      return Fk:getCardById(to_select).color == Card.Red
    end,
    view_as = function(self, cards)
      if #cards ~= 1 then
        return nil
      end
      local c = Fk:cloneCard(self.interaction.data)
      c.skillName = self.name
      c:addSubcards(cards)
    return c
    end,
    before_use = function(self, player, use)
      local room = player.room
      room:setPlayerMark(player, "@@wangxianghong-turn", 1)
    end,
    after_use = function(self, player, _)
      local room = player.room
      local availableTargets = table.map(table.filter(room.alive_players, function(p) 
        return not p.chained
      end), function(p)
        return p.id
      end)
      if #availableTargets == 0 then return false end
      local targets = room:askForChoosePlayers(player, availableTargets, 1, 1, "#wanxiang-target", self.name,true)
        if #targets~=0 then
        room:getPlayerById(targets[1]):setChainState(true)
        end
    end,
    enabled_at_play = function(self, player)
      return player:getMark("@@wangxianghong-turn") == 0 and
        #player:getCardIds("h") >= 1
    end,
    enabled_at_response = function(self, player)
      return player:getMark("@@wangxianghong-turn") == 0 and
        #player:getCardIds("h") >= 1
    end,
  }
  local wanxianghei = fk.CreateViewAsSkill{
    name = "wanxianghei",
    pattern = ".",
    interaction = function()
      local all_names = {}
      for _, id in ipairs(Fk:getAllCardIds()) do
        local card = Fk:getCardById(id)
        if card:isCommonTrick() and not card.is_damage_card and not card.is_derived and
          Self:canUse(card) and not Self:prohibitUse(card) then
          table.insertIfNeed(all_names, card.name)
        end
      end
        return UI.ComboBox { choices = all_names, all_choices = all_names }
    end,
      card_filter = function(self, to_select, selected)
          if #selected > 1 then
              return false
          end
        return Fk:getCardById(to_select).color == Card.Black
      end,
      view_as = function(self, cards)
        if #cards ~= 1 then
          return nil
        end
        local c = Fk:cloneCard(self.interaction.data)
        c.skillName = self.name
        c:addSubcards(cards)
      return c
      end,
      before_use = function(self, player, use)
        local room = player.room
        room:setPlayerMark(player, "@@wanxianghei-turn", 1)
      end,
      after_use = function(self, player, _)
        local room = player.room
        local availableTargets = table.map(table.filter(room.alive_players, function(p) 
          return not p.chained
        end), function(p)
          return p.id
        end)
        if #availableTargets == 0 then return false end
        local targets = room:askForChoosePlayers(player, availableTargets, 1, 1, "#wanxiang-target", self.name,true)
        if #targets~=0 then
        room:getPlayerById(targets[1]):setChainState(true)
        end
      end,
      enabled_at_play = function(self, player)
        return player:getMark("@@wanxianghei-turn") == 0 and
          #player:getCardIds("h") >= 1
      end,
      enabled_at_response = Util.FalseFunc,
    }
    local wanxiang_trigger = fk.CreateTriggerSkill{
      name = "#wanxiang_trigger",
      mute = true,
      events = {fk.Damaged},
      frequency = Skill.Compulsory,
      can_trigger = function(self, event, target, player, data)
        return target == player and (player:getMark("@@wanxianghei-turn") > 0 or player:getMark("@@wangxianghong-turn") > 0)
      end,
      on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "@@wanxianghei-turn",0)
        room:setPlayerMark(player, "@@wangxianghong-turn",0)
      end,
    }
    local mingxiang = fk.CreateTriggerSkill{
      name = "mingxiang",
      anim_type = "control",
      events = {fk.Damage},
      can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and data.to ~= player and data.damageType ~= fk.NormalDamage and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and not target:isNude()
      end,
      on_cost = function(self, event, target, player, data)
        return player.room:askForSkillInvoke(player, self.name, nil, "#mingxiang::"..data.to.id)
      end,
      on_use = function(self, event, target, player, data)
        local room = player.room
        room:doIndicate(player.id, {data.to.id})
        U.viewCards(player, data.to:getCardIds("he"))
        local suits = {}
      for _, id in ipairs(data.to:getCardIds("he")) do
      local suit = Fk:getCardById(id):getSuitString(true)
      if suit ~= "log_nosuit" then
        table.insertIfNeed(suits, suit)
      end
    end
    local choices = room:askForChoices(player, suits, 1, 1, self.name)
    local cards = table.filter(data.to:getCardIds("he"), function (id)
      return not data.to:prohibitDiscard(Fk:getCardById(id)) and table.contains(choices, Fk:getCardById(id):getSuitString(true))
    end)
        if #cards > 0 then
          room:throwCard(cards, self.name, data.to, player)
          if not player.dead then
            player:drawCards(#cards, self.name)
          end
        end
      end,
    }
  jingshangshuncai:addSkill(wanxianghong)
  jingshangshuncai:addSkill(wanxianghei)
  wanxianghong:addRelatedSkill(wanxiang_trigger)
  jingshangshuncai:addSkill(mingxiang)

  Fk:loadTranslationTable{
    ["jingshangshuncai"] = "井上顺菜",
    ["#jingshangshuncai"] = "金镲法王",
    ["wanxianghong"] = "万象(红)",
    [":wanxianghong"] = "每回合限一次,你可以将一张红色牌当做一张普通基本牌使用或打出。当你发动此技能时,你可以令一名角色进入连环状态，当你受到属性伤害时,此技能本回合视为未发动过。",
    ["wanxianghei"] = "万象(黑)",
    [":wanxianghei"] = "每回合限一次,你可以将一张黑色牌当做一张非伤害类普通锦囊牌使用或打出。当你发动此技能时,你可以令一名角色进入连环状态，当你受到属性伤害时,此技能本回合视为未发动过。",
    ["@@wangxianghong-turn"] = "万象（红）",
    ["@@wanxianghei-turn"] = "万象（黑）",
    ["mingxiang"] = "鸣响",
    ["#mingxiang::"] = "是否发动鸣响",
    [":mingxiang"] = "每回合限一次，当你对一名角色造成属性伤害时,你可以观看其手牌并弃置其区域内一种花色的所有牌,然后你摸等量的牌。",
    ["#mingxiang"] = "选择一种花色，弃置%dest该花色的牌。",
    ["#wanxiang-target"] = "万象：横置一名角色",
  }


  local niaozhonghongyin = General:new(extension,"niaozhonghongyin","th_k_chui",4,4,General.Female)
  local tiaoyin = fk.CreateTriggerSkill{
    name = "tiaoyin",
    anim_type = "control",
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and player.phase == Player.Finish
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local x = player:getAttackRange()
      local targets = room:getAlivePlayers()
      room:doIndicate(player.id, table.map(targets, Util.IdMapper))
      for _, p in ipairs(targets) do
        if not p.dead then
          if #room:askForDiscard(p, 1, 1, true, self.name, true, ".", "#tiaoyin-discard::"..player.id) == 0 then
            p:drawCards(1, self.name)
            if player.dead then return false end
          end
        end
      end
      x = player:getAttackRange()
       local targets1 = table.map(table.filter(targets, function(p)
          return p:getHandcardNum() == x end), Util.IdMapper)
        if #targets1 > 0 then
          local y = #targets1
          player:drawCards(y, self.name)
        end
        x = player:getAttackRange()
        targets1 = table.map(table.filter(targets, function(p)
        return not p.dead and p:getHandcardNum() ~= x end), Util.IdMapper)
      local to = room:askForChoosePlayers(player, targets1, 1, 1, "#tiaoyin-damage", self.name, true)
      if #to > 0 then
        room:damage{
          from = player,
          to = room:getPlayerById(to[1]),
          damage = 1,
          skillName = self.name,
        }
        if player.dead then return false end
      end
    end
  }
  niaozhonghongyin:addSkill(tiaoyin)
  local nzhy_shouxi = fk.CreateActiveSkill{
    name = "nzhy_shouxi",
    prompt = "#nzhy_shouxi",
    frequency = Skill.Compulsory,
    card_num = 0,
    target_num = 0,
    interaction = function()
      return UI.Spin { from = 1, to = 5 }
    end,
    card_filter = Util.FalseFunc,
    can_use = function(self, player)
      return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      room:setPlayerMark(player, "@nzhy_shouxi", self.interaction.data)
    end,
  }
  local nzhy_shouxi_attackrange = fk.CreateAttackRangeSkill{
    name = "#nzhy_shouxi_attackrange",
    fixed_func = function (self, player)
      if player:hasSkill(nzhy_shouxi) and player:getMark("@nzhy_shouxi") ~= 0 then
        return player:getMark("@nzhy_shouxi")
      end
    end,
  }
  local nzhy_shouxi_filter = fk.CreateFilterSkill{
    name = "#nzhy_shouxi_filter",
    card_filter = function(self, card, player)
      return player:hasSkill(nzhy_shouxi) and card.sub_type == Card.SubtypeWeapon and table.contains(player.player_cards[Player.Hand], card.id)
    end,
    view_as = function(self, card)
      local c = Fk:cloneCard("slash", card.suit, card.number)
      c.skillName = "nzhy_shouxi"
      return c
    end,
  }
  local nzhy_shouxi_targetmod = fk.CreateTargetModSkill{
    name = "#nzhy_shouxi_targetmod",
    bypass_times = function(self, player, skill, scope)
      return player:hasSkill(nzhy_shouxi) and player:getMark("@nzhy_shouxi") == 1 and skill.trueName == "slash_skill" and scope == Player.HistoryPhase
    end,
  }
  local nzhy_shouxi_trigger = fk.CreateTriggerSkill{
    name = "#nzhy_shouxi_trigger",
    mute = true,
    events = {fk.AfterCardUseDeclared, fk.AfterCardTargetDeclared, fk.EventAcquireSkill, fk.GameStart},
    frequency = Skill.Compulsory,
    can_trigger = function(self, event, target, player, data)
      if event == fk.EventAcquireSkill then
        return data == nzhy_shouxi and target == player and player.room:getTag("RoundCount")
      elseif event == fk.GameStart then
        return player:hasShownSkill(nzhy_shouxi, true)
      end
      if player == target and player:hasSkill(nzhy_shouxi) and data.card.trueName == "slash" then
        if event == fk.AfterCardUseDeclared then
          return player:getMark("@nzhy_shouxi") == 2
        else
          return player:getMark("@nzhy_shouxi") == 4 and #U.getUseExtraTargets(player.room, data) > 0
        end
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.EventAcquireSkill or event == fk.GameStart then
        if table.contains(player:getAvailableEquipSlots(), Player.WeaponSlot) then
          room:abortPlayerArea(player, Player.WeaponSlot)
        end
      else
        if player:getMark("@nzhy_shouxi") == 2 then
          data.additionalDamage = (data.additionalDamage or 0) + 1
        else if player:getMark("@nzhy_shouxi") == 4 then
          local to = room:askForChoosePlayers(player, U.getUseExtraTargets(room, data),
          1, 1, "#nzhy_shouxi-choose:::"..data.card:toLogString(), nzhy_shouxi.name, true)
          if #to > 0 then
            table.insert(data.tos, to)
          end
        end
        end
      end
    end,
  }
  local nzhy_shouxi_maxcards = fk.CreateMaxCardsSkill{
    name = "#nzhy_shouxi_maxcards",
    correct_func = function(self, player)
      if player:hasSkill(nzhy_shouxi.name) and player:getMark("@nzhy_shouxi") == 5 then
        return 1
      end
    end
  }
  local nzhy_shouxi_1= fk.CreateTriggerSkill{
    name = "#nzhy_shouxi_1",
    anim_type = "control",
    events = {fk.TargetSpecified},
    frequency = Skill.Compulsory,
    can_trigger = function(self, event, target, player, data)
      if not (target == player and player:hasSkill(self) and data.card.trueName == "slash") then return false end
      local to = player.room:getPlayerById(data.to)
      return not to.dead and not to:isNude() and player:getMark("@nzhy_shouxi") == 3
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:doIndicate(player.id, {data.to})
      local to = room:getPlayerById(data.to)
      room:askForDiscard(to, 1, 1, true, self.name, false)
    end,
  }
  niaozhonghongyin:addSkill(nzhy_shouxi)
  nzhy_shouxi:addRelatedSkill(nzhy_shouxi_filter)
  nzhy_shouxi:addRelatedSkill(nzhy_shouxi_targetmod)
  nzhy_shouxi:addRelatedSkill(nzhy_shouxi_trigger)
  nzhy_shouxi:addRelatedSkill(nzhy_shouxi_attackrange)
  nzhy_shouxi:addRelatedSkill(nzhy_shouxi_maxcards)
  nzhy_shouxi:addRelatedSkill(nzhy_shouxi_1)
  Fk:loadTranslationTable{
    ["niaozhonghongyin"] = "鸟冢弘音",
    ["#niaozhonghongyin"] = "单簧管首席",
    ["tiaoyin"] = "调音",
    [":tiaoyin"] = "结束阶段开始时，你可以令所有角色依次选择一项：1.摸一张牌；2.弃置一张牌。选择完成后你摸x张牌（x为手牌数与你攻击距离相同的角色数），然后你可以对手牌数不等于你攻击距离的一名角色造成一点伤害。",
    ["#tiaoyin-discard"] = "弃置一张牌，否则摸一张牌",
    ["#tiaoyin-damage"] = "选择一名角色，对其造成一点伤害",
    ["@nzhy_shouxi"] = "攻击距离",
    ["#nzhy_shouxi-choose:::"] = "选择一名额外目标。",
    ["nzhy_shouxi"] = "首席",
    [":nzhy_shouxi"] = "你废除乐器栏且始终视为装备“单簧管”，你的武器牌均视为杀。单簧管：出牌阶段限一次，你可以调整攻击范围（1~5）。1：使用【杀】无次数限制；2：使用【杀】伤害+1；3：使用【杀】指定目标后令目标弃置一张牌；4：使用【杀】可额外选择一个目标；5：手牌上限+1。",
    ["#nzhy_shouxi"] = "调整你的攻击范围",
    ["#nzhy_shouxi_filter"] = "首席",
    ["#nzhy_shouxi_targetmod"] = "首席",
    ["#nzhy_shouxi_1"] = "首席",
    ["#nzhy_shouxi_maxcards"] = "首席",
    ["#nzhy_shouxi_attackrange"] = "首席",
  }
  local jiushizou = General:new(extension,"jiushizou","th_k_chui3",3,3,General.Female)
  local cuxia = fk.CreateTriggerSkill{
  name = "cuxia",
  anim_type = "drawcard",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local x = player.hp
    player:drawCards(x, "cuxia")
    local cards = player.room:askForCard(player, x, x, false, self.name, false)
    player:addToPile("cuxia", cards, false, self.name)
    end
  }
  local cuxiadis = fk.CreateTriggerSkill{
    name = "#cuxiadis",
    anim_type = "drawcard",
    events = {fk.EventPhaseStart},
    frequency = Skill.Compulsory,
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and player.phase == Player.Start and #player:getPile("cuxia") > 0 and player:hasSkill(cuxia)
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:moveCards({
      from = player.id,
      ids = player:getPile("cuxia"),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonPutIntoDiscardPile,
      skillName = "cuxia",
      specialName = "cuxia",
    })
  end
  }
  local cuxia_trigger = fk.CreateTriggerSkill{
    name = "#cuxia_trigger",
    events = {fk.CardRespondFinished, fk.CardUseFinished},
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(cuxia)
      and #player:getPile("cuxia") > 0 and 
      table.find(player:getPile("cuxia"), function(id) return Fk:getCardById(id).trueName == data.card.trueName
        end)
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local tos = data.from
      local cards = player:getPile("cuxia")
      player:drawCards(1,self.name)
      local choices = {"gain", "give"}
      local choice = room:askForChoice(player, choices, self.name)
      local id = room:askForCardChosen(player, player, { card_data = { { "cuxia", cards } } }, self.name)
      if choice == "gain" then
        room:obtainCard(player, id, true, fk.ReasonPrey)
      else if choice == "give" then
        room:obtainCard(tos, id, true, fk.ReasonPrey)
        room:damage {
          from = player,
          to = room:getPlayerById(tos),
          damage = 1,
          skillName = self.name,
        }
      end
      end
    end,
  }
  local qiuan = fk.CreateTriggerSkill{
    name = "qiuan",
    events = {fk.DamageInflicted},
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and not player:isNude() and data.from and data.from ~= player
        and not data.from.dead and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local get = room:askForCardChosen(player, player, "he", self.name)
        room:obtainCard(data.from, get, false, fk.ReasonPrey)
        return true
    end,
  }
  local zhinuan = fk.CreateTriggerSkill{
    name = "zhinuan",
    frequency = Skill.Wake,
    events = {fk.EventPhaseStart,fk.EnterDying},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and
        player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
        (player.phase == Player.Start or player.phase == Player.Finish or player.dying)
    end,
    can_wake = function(self, event, target, player, data)
      return player:isKongcheng() or player.dying
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:changeMaxHp(player, 1)
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      if player.dead then return false end
      room:handleAddLoseSkills(player, "rechen", nil)
      room:handleAddLoseSkills(player, "-qiuan", nil)
    end,
  }
  local rechen = fk.CreateActiveSkill{
    name = "rechen",
    anim_type = "support",
    can_use = function(self, player, card)
      return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    min_card_num = 2,
    max_card_num = 2,
    card_filter = function(self, to_select, selected)
      return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand and #selected < 2
    end,
    target_num = 1,
    target_filter = function(self, to_select, selected)
      return to_select ~= Self.id and #selected == 0
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local target = room:getPlayerById(effect.tos[1])
      local cards = table.map(effect.cards, Util.Id2CardMapper)
      room:obtainCard(target, cards, false, fk.ReasonGive)
      local getcard = room:askForCard(target, 2, 2, true, self.name,false)
      room:obtainCard(player, getcard, false, fk.ReasonGive)
      if  table.find(getcard, function (id)
        return Fk:getCardById(id).suit == Card.Heart
      end) then
        player:drawCards(1,self.name)
      end
    end,
  }
  local chuandaolvhui = General:new(extension,"chuandaolvhui","th_k_chui1",5,5,General.Female)
  local shengxin_maxhp = fk.CreateTriggerSkill{
    name = "#shengxin_maxhp",
    events = {fk.GameStart},
    frequency = Skill.Compulsory,
    mute = true,
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and player.maxHp~=5
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local n = 5-player.maxHp
      room:changeMaxHp(player, n)
    end,
  }
  local shengxin = fk.CreateTriggerSkill{
    name = "shengxin",
    anim_type = "drawcard",
    events = {fk.TurnStart},
    frequency = Skill.Compulsory,
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self)
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local n = 5 - player:getHandcardNum()
      if n>0 then
        player:drawCards(n)
      end
      if n<0 then
        room:askForDiscard(player, -n, -n, false, self.name, false)
      end
    end,
  }
  local shengxin_draw = fk.CreateTriggerSkill{
    name = "#shengxin_draw",
    events = {fk.EventPhaseChanging},
    frequency = Skill.Compulsory,
    mute = true,
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and data.to == Player.Draw
    end,
    on_use = function(self, event, target, player, data)
      player:skip(player.Draw)
      return true
    end
  }
  local shengxin_demage = fk.CreateTriggerSkill{
    name = "#shengxin_demage",
    anim_type = "masochism",
    events = {fk.Damaged},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and not player:isNude()
    end,
    on_cost = function(self, event, target, player, data)
      local prompt = "#shengxin_demage-invoke"
      local cards = player.room:askForDiscard(player, 1, 2, false, self.name, true, ".", prompt, true)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local cards = self.cost_data
      room:throwCard(cards, self.name, player, player)
    end,
  }
  local chunyin = fk.CreateFilterSkill{
    name = "chunyin",
    card_filter = function(self, to_select, player)
      --FIXME: filter skill isn't status skill, can't filter card which exists before hp change
      return player:hasSkill(self) and player.phase == Player.Play and to_select.name == "jink" and
      table.contains(player.player_cards[Player.Hand], to_select.id)
    end,
    view_as = function(self, to_select)
      return Fk:cloneCard("slash", to_select.suit, to_select.number)
    end,
  }
  local fukan = fk.CreateActiveSkill{
    name = "fukan",
    anim_type = "special",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
      return (player:getMark("@@fukanbasic-phase") == 0 or player:getMark("@@fukantrick-phase") == 0 or player:getMark("@@fukanequip-phase") == 0) and player:getMark("@@fukanshixiao-phase") == 0
    end,
    interaction = function()
      local choices = {}
      if Self:getMark("@@fukanbasic-phase") == 0 then table.insert(choices, "basic") end
      if Self:getMark("@@fukantrick-phase") == 0 then table.insert(choices, "trick") end
      if Self:getMark("@@fukanequip-phase") == 0 then table.insert(choices, "equip") end
      return UI.ComboBox {choices = choices }
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected)
      if #selected == 0 then
        return not table.contains(U.getMark(Self, "fukan-phase"), to_select)
      end
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local target = room:getPlayerById(effect.tos[1])
      local mark = U.getMark(player, "fukan-phase")
      table.insertIfNeed(mark, target.id)
      room:setPlayerMark(player, "fukan-phase", mark)
      if self.interaction.data == "basic" then
        room:addPlayerMark(player, "@@fukanbasic-phase",1)
        U.viewCards(player, target:getCardIds(Player.Hand), self.name)
        local handcards = target:getCardIds(Player.Hand)
        local basic = table.filter(handcards, function (id)
          return Fk:getCardById(id).type == Card.TypeBasic
        end)
        if #basic~=0 then
          player.room:setPlayerMark(player, "@@fukanslash", 1)
        else room:addPlayerMark(player, "@@fukanshixiao-phase",1)
        end
      end
      if self.interaction.data == "trick" then
        room:addPlayerMark(player, "@@fukantrick-phase",1)
        U.viewCards(player, target:getCardIds(Player.Hand), self.name)
        local handcards = target:getCardIds(Player.Hand)
        local trick = table.filter(handcards, function (id)
          return Fk:getCardById(id).type == Card.TypeTrick
        end)
        if #trick~=0 then
          player.room:setPlayerMark(player, "@@fukanslash", 1)
        else room:addPlayerMark(player, "@@fukanshixiao-phase",1)
        end
      end
      if self.interaction.data == "equip" then
        room:addPlayerMark(player, "@@fukanequip-phase",1)
        U.viewCards(player, target:getCardIds(Player.Hand), self.name)
        local handcards = target:getCardIds(Player.Hand)
        local equip = table.filter(handcards, function (id)
          return Fk:getCardById(id).type == Card.TypeEquip
        end)
        if #equip~=0 then
          player.room:addPlayerMark(player, "@@fukanslash", 1)
        else room:addPlayerMark(player, "@@fukanshixiao-phase",1)
        end
      end
    end,
  }
  local fukan_targetmod = fk.CreateTargetModSkill{
    name = "#fukan_targetmod",
    bypass_times = function(self, player, skill, scope, card, to)
      return player:getMark("@@fukanslash") > 0
    end,
    bypass_distances =  function(self, player, skill, card, to)
      return player:getMark("@@fukanslash") > 0
    end,
  }
  local fukan_refresh = fk.CreateTriggerSkill{
    name = "#fukan_refresh",
    mute = true,
    events = {fk.CardUseFinished},
    frequency = Skill.Compulsory,
    can_trigger = function(self, event, target, player, data)
        return  player:hasSkill(self) and data.card.trueName == "slash" and player:getMark("@@fukanslash") ~= 0
    end,
    on_use = function(self, event, target, player, data)
      player.room:setPlayerMark(player, "@@fukanslash", 0)
    end
  }

  jiushizou:addSkill(qiuan)
  jiushizou:addSkill(cuxia)
  cuxia:addRelatedSkill(cuxiadis)
  cuxia:addRelatedSkill(cuxia_trigger)
  jiushizou:addSkill(zhinuan)
  jiushizou:addRelatedSkill(rechen)
  chuandaolvhui:addSkill(shengxin)
  shengxin:addRelatedSkill(shengxin_maxhp)
  shengxin:addRelatedSkill(shengxin_draw)
  shengxin:addRelatedSkill(shengxin_demage)
  chuandaolvhui:addSkill(chunyin)
  chuandaolvhui:addSkill(fukan)
  fukan:addRelatedSkill(fukan_targetmod)
  fukan:addRelatedSkill(fukan_refresh)
  Fk:loadTranslationTable{
    ["jiushizou"] = "久石奏",
    ["#jiushizou"] = "小恶魔",
    ["cuxia"] = "促狭",
    [":cuxia"] = "准备阶段，你可以摸X张牌，然后将等量张牌暗置于武将牌上,直到你下个回合开始。当一名角色使用或打出牌时,若你武将牌上包含同牌名的暗置牌，你可以摸一张牌并选择一项:1.获得武将牌上一张暗置牌,2.将一张暗置牌交于该角色并对其成1点伤害。（X为你的体力值)",
    ["#cuxiadis"] = "促狭",
    ["#cuxia_trigger"] = "促狭",
    ["gain"] = "获得一张促狭牌",
    ["give"] = "交给%dest一张促狭牌并对其造成一点伤害",
    ["qiuan"] = "求安",
    [":qiuan"] = "每回合限一次,当你受到伤害时,你可以交于伤害来源一张牌,然后防止此伤害。",
    ["zhinuan"] = "知暖",
    [":zhinuan"] = "觉醒技:当你没有手牌或进入濒死时，你增加1点体力上限并回复1点体力,获得“热枕”，然后失去“求安”。",
    ["rechen"] = "热忱",
    [":rechen"] = "出牌阶段限一次，你可以交给一名角色两张牌，然后其交给你两张牌。若你以此法获得的牌含有红桃花色，则你摸一张牌",
    ["chuandaolvhui"] = "川岛绿辉",
    ["#chuandaolvhui"] = "大魔王",
    ["shengxin"] = "圣心",
    [":shengxin"] = "锁定技:你的体力上限始终为5。你始终跳过摸牌阶段，每名角色回合开始时,你将手牌数调整至体力上限。当你受到伤害时你可以弃置至多两张牌。",
    ["chunyin"] = "纯音",
    [":chunyin"] = "锁定技:你的回合内，你的闪均视为杀。",
    ["#shengxin_maxhp"] = "圣心",
    ["#shengxin_draw"] = "圣心",
    ["#shengxin_demage"] = "圣心",
    ["#shengxin_demage-invoke"] = "圣心：你可以弃置至多两张牌。",
    ["fukan"] = "俯瞰",
    [":fukan"] = "出牌阶段,你可以选择一种类型的牌,然后观看一名本回合未以此法选择过的角色的手牌,若其中含有该类型的牌,则你本回合使用的下一张杀无距离和次数限制;否则此技能本回合失效。(每回合每种类型限一次)",
    ["@@fukanslash"] = "俯瞰",
    ["@@fukanshixiao-phase"] = "俯瞰失效",
    ["@@fukanbasic-phase"] = "基本",
    ["@@fukantrick-phase"] = "锦囊",
    ["@@fukanequip-phase"] = "装备",
    ["#fukan_refresh"] = "俯瞰",
  }


  local heijiangzhenyou = General:new(extension,"heijiangzhenyou","th_k_wai",4,4,General.Female)
  local eup_kunjue = fk.CreateActiveSkill{
    name = "eup_kunjue",
    anim_type = "offensive",
    target_num = 1,
    can_use = function(self, player)
      return (player:getMark("eup_kunjue_lose-phase") == 0 or player:getMark("eup_kunjue_discard-phase") == 0) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
    end,
    target_filter = function(self, to_select, selected)
      return #selected == 0 and to_select ~= Self.id
      end,
    card_filter = Util.FalseFunc,
    interaction = function()
      local choices = {}
      if Self:getMark("eup_kunjue_lose-phase") == 0 then table.insert(choices, "eup_kunjue_lose") end
      if Self:getMark("eup_kunjue_discard-phase") == 0 then table.insert(choices, "eup_kunjue_discard") end
      return UI.ComboBox {choices = choices }
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local to = room:getPlayerById(effect.tos[1])
      room:setPlayerMark(player, self.interaction.data.."-phase", 1)
      if player.dead then return end
      player:drawCards(1)
      if self.interaction.data == "eup_kunjue_lose" then
        room:loseHp(player, 1, self.name)
        room:useVirtualCard("duel", nil, player, to, self.name, false)
      else
        room:askForDiscard(player,2,2,true,self.name,false)
        room:useVirtualCard("duel", nil, player, to, self.name, false)
    end
    end
  }
  local eup_kunjue1 = fk.CreateActiveSkill{
    name = "eup_kunjue1",
    anim_type = "offensive",
    target_num = 1,
    can_use = function(self, player)
      return (player:getMark("eup_kunjue_lose-phase") == 0 or player:getMark("eup_kunjue_discard-phase") == 0)
    end,
    target_filter = function(self, to_select, selected)
      return #selected == 0 and to_select ~= Self.id
      end,
    card_filter = Util.FalseFunc,
    interaction = function()
      local choices = {}
      if Self:getMark("eup_kunjue_lose-phase") == 0 then table.insert(choices, "eup_kunjue_lose") end
      if Self:getMark("eup_kunjue_discard-phase") == 0 then table.insert(choices, "eup_kunjue_discard") end
      return UI.ComboBox {choices = choices }
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local to = room:getPlayerById(effect.tos[1])
      room:setPlayerMark(player, self.interaction.data.."-phase", 1)
      if player.dead then return end
      player:drawCards(1)
      if self.interaction.data == "eup_kunjue_lose" then
        room:loseHp(player, 1, self.name)
        room:useVirtualCard("duel", nil, player, to, self.name, false)
      else
        room:askForDiscard(player,2,2,true,self.name,false)
        room:useVirtualCard("duel", nil, player, to, self.name, false)
    end
    end
  }
  local eup_shuli = fk.CreateTriggerSkill{
    name = "eup_shuli",
    anim_type = "special",
    frequency = Skill.Compulsory,
    events = {fk.GameStart},
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self)
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:addPlayerMark(player, "@shuli", player.hp)
    end,
  }
  local eup_shuli1 = fk.CreateTriggerSkill{
    name = "#eup_shuli1",
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and player.phase == Player.Start and player:getMark("@shuli") > 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      player:drawCards(1, self.name)
      room:removePlayerMark(player, "@shuli", 1)
    end,
  }
  local eup_shuli2 = fk.CreateTriggerSkill{
    name = "#eup_shuli2",
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    events = {fk.PreHpRecover},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and player:getMark("@shuli") > 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      player:drawCards(1, self.name)
      room:removePlayerMark(player, "@shuli", 1)
    end,
  }
  local eup_shuli1distance = fk.CreateDistanceSkill{
    name = "#eup_shuli1distance",
    correct_func = function(self, from, to)
      return to:getMark("@shuli")
    end,
  }
  local eup_shuli3 = fk.CreateTriggerSkill{
    name = "#eup_shuli3",
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and
        player.phase == Player.Finish and player:getMark("@shuli") == 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:handleAddLoseSkills(player, "-eup_shuli", nil, true, false)
      room:handleAddLoseSkills(player, "-eup_kunjue", nil, true, false)
      room:handleAddLoseSkills(player, "eup_kunjue1", nil, true, false)
    end,
  }
  eup_shuli:addRelatedSkill(eup_shuli1)
  eup_shuli:addRelatedSkill(eup_shuli3)
  eup_shuli:addRelatedSkill(eup_shuli2)
  eup_shuli:addRelatedSkill(eup_shuli1distance)
  heijiangzhenyou:addSkill(eup_shuli)
  local eup_weipo = fk.CreateTriggerSkill{
    name = "eup_weipo",
    anim_type = "offensive",
    events ={fk.CardResponding},
    can_trigger = function(self, event, target, player, data)
      local from = player.room:getPlayerById(data.from)
      if event == fk.CardResponding and player:hasSkill(self.name) and data.card.trueName == "slash"  and player:getMark("@@eup_weipo1-turn") == 1 then
        return data.responseToEvent and
        data.responseToEvent.card.name =="duel"
      elseif player:hasSkill(self.name) and data.card then
        return target == player and
        data.card.name =="duel" and not data.to.dead and not data.to:isNude()
      end
    end,
    on_cost = function(self, event, target, player, data)
      if event == fk.CardResponding then return true end
      local room = player.room
      return room:askForSkillInvoke(player,self.name)
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:addPlayerMark(player,"@@eup_weipo-turn",1)
      end
  }
  heijiangzhenyou:addSkill(eup_weipo)
  local eup_weipo1 = fk.CreateTriggerSkill{
    name = "#eup_weipo1",
    mute = true,
    frequency = Skill.Compulsory,
    events ={fk.TargetSpecified},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and  data.card.trueName == "duel" and target==player
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:addPlayerMark(player,"@@eup_weipo1-turn",1)
    end,
  }
  eup_weipo:addRelatedSkill(eup_weipo1)
  local eup_weipo_trigger = fk.CreateTriggerSkill{
    name = "#eup_weipo_trigger",
    mute = true,
    events = {fk.DamageCaused},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:getMark("@@eup_weipo-turn")>0 and data.by_user
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
      local room = player.room
      player:broadcastSkillInvoke("eup_weipo")
      room:notifySkillInvoked(player, "eup_weipo")
      data.damage = data.damage + 1
    end,
  }
  eup_weipo:addRelatedSkill(eup_weipo_trigger)
  local eup_weipo2 = fk.CreateTriggerSkill{
    name = "#eup_weipo2",
    anim_type = "negative",
    frequency = Skill.Compulsory,
    events = {fk.TargetConfirmed},
    can_trigger = function(self, event, target, player, data)
      local from = player.room:getPlayerById(data.from)
      return player:hasSkill(self) and from:isNude() and from ~= player and data.card.trueName == "duel"
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
    player:broadcastSkillInvoke(self.name)
    if event == fk.TargetConfirmed then
      data.disresponsive = true
      end
    end,
  }
  eup_weipo:addRelatedSkill(eup_weipo2)
  heijiangzhenyou:addSkill(eup_kunjue)
  heijiangzhenyou:addRelatedSkill(eup_kunjue1)
  Fk:loadTranslationTable{
    ["heijiangzhenyou"] = "黑江真由",
    ["#heijiangzhenyou"] = "困顿难行",
    ["#eup_shuli1"] = "疏离",
    ["#eup_shuli2"] = "疏离",
    ["#eup_shuli3"] = "疏离",
    ["eup_shuli"] = "疏离",
    [":eup_shuli"] ="锁定技:游戏开始时，其他角色与你计算距离+X。准备阶段或你回复体力时，你摸一张牌，然后X的数值-1;结束阶段，若x为0则你失去“疏离”，并修改“困决”为出牌阶段各限一次。(×为游戏开始时你的体力值)",
    ["@shuli"] = "疏离",
    ["eup_weipo"] = "危迫",
    ["#eup_weipo1"] = "危迫",
    [":eup_weipo"] = "锁定技:你每回合首次使用的“独奏之争”被响应时，你对其他角色造成的伤害+1;当你成为“独奏之争”的目标时，若使用者没有手牌，则你无法响应此牌。",
    ["@@eup_weipo-turn"] = "加伤",
    ["@@eup_weipo1-turn"] = "危迫",
    ["#eup_weipo_trigger"] = "危迫",
    ["eup_kunjue"] = "困决",
    [":eup_kunjue"] = "出牌阶段限一次，你可以摸一张牌并执行一项:1.失去1点体力;2.弃置两张牌;然后视为使用一张“独奏之争”。",
    ["eup_kunjue1"] = "困决",
    [":eup_kunjue1"] = "出牌阶段每项各限一次，你可以摸一张牌并执行一项:1.失去1点体力;2.弃置两张牌;然后视为使用一张“独奏之争”。",
    ["eup_kunjue_lose"] = "失去1点体力",
    ["eup_kunjue_discard"] = "弃置两张牌",
  }
  local jiewanshazi = General:new(extension,"jiewanshazi","th_k_chui1",4,4,General.Female)
  local eup_wangming = fk.CreateTriggerSkill{
    name = "eup_wangming",
    frequency = Skill.Compulsory,
    anim_type = "drawcard",
    events = {fk.ChainStateChanged},
    can_trigger = function(self, event, target, player, data)
      if player:hasSkill(self) and not target.dead then
        return event == fk.ChainStateChanged and target.chained and target==player
      end
    end,
    on_use = function(self, event, target, player, data)
      target:drawCards(2, self.name)
    end,
  }
  local eup_wangming1 = fk.CreateTriggerSkill{
    name = "#eup_wangming1",
    frequency = Skill.Compulsory,
    anim_type = "defensive",
    events = {fk.ChainStateChanged},
    can_trigger = function(self, event, target, player, data)
      if player:hasSkill(self) and not target.dead then
        return event == fk.ChainStateChanged and not target.chained and target==player
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end,
  }
  jiewanshazi:addSkill(eup_wangming)
  eup_wangming:addRelatedSkill(eup_wangming1)
  local eup_leigu = fk.CreateActiveSkill{
    name = "eup_leigu",
    anim_type = "offensive",
    prompt = "#eup_leigu-active",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
      return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected)
      local target = Fk:currentRoom():getPlayerById(to_select)
      return #selected == 0 and Self:canPindian(target)
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local target = room:getPlayerById(effect.tos[1])
      local pindian = player:pindian({target}, self.name)
      if pindian.results[target.id].winner == player and not player.dead and not target.dead then
        local slash = Fk:cloneCard("fire__slash")
        slash.skillName = self.name
        local targets = table.filter(room.alive_players, function (p)
          return not (p == player or p == target or p:prohibitUse(slash) or p:isProhibited(target, slash))
        end)
        if #targets == 0 then return false end
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper),
        1, 1, "#eup_leigu-choose::" .. effect.tos[1], self.name, true, true)
        if #tos > 0 then
          room:useCard({
            from = tos[1],
            tos = {effect.tos},
            card = slash,
            extraUse = true,
          })
        end
      else if not player.chained then
        player:setChainState(true)
      end
      end
    end,
  }
  local eupleigu_trigger = fk.CreateTriggerSkill{
    name = "#eupleigu_trigger",
    mute = true,
    events = {fk.Damaged},
    prompt = "#eupleigu-active",
    can_trigger = function(self, event, target, player, data)
      return target == player
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local availableTargets = table.map(table.filter(room.alive_players, function(p) 
        return not p.chained
      end), function(p)
        return p.id
      end)
      if #availableTargets == 0 then return false end
      local targets = room:askForChoosePlayers(player, availableTargets, 1, 1, "#wanxiang-target", self.name,true)
        if #targets~=0 then
        room:getPlayerById(targets[1]):setChainState(true)
        end
    end,
  }
  jiewanshazi:addSkill(eup_leigu)
  eup_leigu:addRelatedSkill(eupleigu_trigger)
  Fk:loadTranslationTable{
    ["jiewanshazi"] = "堺万纱子",
    ["#jiewanshazi"] = "路人王",
    ["eup_wangming"] = "望名",
    [":eup_wangming"] = "锁定技:当你进入连环状态时，你摸两张牌;当你解除连环状态时，你回复1点体力。",
    ["eup_leigu"] = "擂鼓",
    [":eup_leigu"] = "出牌阶段限一次，你可以与一名角色进行拼点;若你赢，则你可以令一名其他角色视为对该角色使用一张无视距离的火杀;若你没赢，你进入连环状态。当你受到伤害后，你可以令一名角色进入连环状态。",
    ["#eupleigu_trigger"] = "擂鼓",
    ["#eup_wangming1"] = "望名",
    ["#eup_leigu-active"] = "擂鼓：你可以拼点，若没赢，你进入连环状态：若你赢，你可以令另一名角色视为其对一名其他角色使用火【杀】】",
    ["#eup_leigu-choose"] = "擂鼓：你可以选择一名角色，视为其对 %dest 使用火【杀】",
    ["#eup_leigu1-choose"] = "擂鼓：选择一名角色，成为火【杀】目标",
    ["#eupleigu-active"] = "选择一名角色，令其进入连环状态",
  }
return extension